﻿<Window x:Class="IGL_Talk_Windows_Desktop.View.ChatView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ap="clr-namespace:IGL_Talk_Windows_Desktop.AttachedProperties"
        ap:DialogCloser.DialogResult="{Binding CloseChatView}"
        Title="IGL Talk - InfoGeoLog Chat" Height="460" Width="680" 
        WindowStartupLocation="CenterScreen" ResizeMode="NoResize" WindowStyle="None" AllowsTransparency="True"
        Background="Transparent" FontFamily="Segoe UI" >
    <Window.Resources>
        <DataTemplate x:Key="MessagesTemplate">
            <Border x:Name="MessageStackPanel" BorderBrush="#FFEAEAEA" BorderThickness="1" Padding="5">
                <StackPanel Width="480" >
                    <TextBlock x:Name="mAuthor">
                    <Run  FontWeight="Bold" Text="{Binding Message.User.Name}"/>
                    <Run Text=" says: "/>
                    </TextBlock>
                    <TextBlock TextWrapping="WrapWithOverflow" Text="{Binding Message.Text}"/>
                    <TextBlock x:Name="mDate">
                    <Run Text="("/>
                    <Run  Text="{Binding Message.Date}"/>
                    <Run Text=")"/>
                    </TextBlock>
                </StackPanel>
            </Border>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding IsNew}" Value="True">
                    <Setter TargetName="MessageStackPanel" Property="Background" Value="#FFF1F4FD"/>
                    <Setter TargetName="MessageStackPanel" Property="Style" Value="{DynamicResource NewMessageAnimationStyle}"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding IsNew}" Value="False">
                    <Setter TargetName="MessageStackPanel" Property="Background" Value="White"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding IsNotification}" Value="True">
                    <Setter TargetName="mAuthor" Property="Visibility" Value="Collapsed"/>
                    <Setter TargetName="mDate" Property="Visibility" Value="Collapsed"/>
                    <Setter TargetName="MessageStackPanel" Property="Background" Value="#FFF7f7f9"/>
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
        <DataTemplate x:Key="UsersTemplate">
            <StackPanel>
                <TextBlock x:Name="uName" Foreground="#FFCFCFCF" Text="{Binding User.Name}"/>
            </StackPanel>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding IsCurrentUser}" Value="True">
                    <Setter TargetName="uName" Property="Foreground" Value="#FFFFFFFF"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding IsCurrentUser}" Value="False">
                    <Setter TargetName="uName" Property="Foreground" Value="#FFC7C7C7"/>
                    <Setter TargetName="uName" Property="FontWeight" Value="Bold"/>
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
    </Window.Resources>
    <Border CornerRadius="2">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <StackPanel Grid.Row="0" Orientation="Horizontal" Background="{DynamicResource BlueGradient2}" MouseLeftButtonDown="StackPanel_MouseLeftButtonDown">
                <StackPanel HorizontalAlignment="Left" Margin="20,10">
                    <Label FontSize="20" Foreground="White" >
                        IGLTalk
                    </Label>
                </StackPanel>
                <StackPanel HorizontalAlignment="Right" Margin="480,0,0,0" VerticalAlignment="Top"  >
                    <Button Command="{Binding CloseWindowCommand}" Style="{DynamicResource CloseButton}" FontFamily="Arial" HorizontalAlignment="Right" FontSize="14" Content="x"/>
                    <Button Command="{Binding LogoutCommand}" Style="{DynamicResource CloseButton}" Margin="25,5" FontSize="10" Content="Logout"/>
                </StackPanel>
            </StackPanel>
            <Grid Grid.Row="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="200"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid Grid.Column="0">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <StackPanel Grid.Row="0" Height="70" Background="White" Orientation="Horizontal" >
                        <Image Margin="10" Source="..\avatar.jpg" Height="50"/>
                        <Label Content="{Binding UserName}" VerticalAlignment="Center"/>
                    </StackPanel>
                    <StackPanel Grid.Row="1" Background="{DynamicResource GreyGradient}">
                        <Label Margin="10,5" FontSize="13" Foreground="White" Content="Chat users"/>
                        <ListView  FontSize="12" BorderThickness="0" Background="#FF282E3D" 
                              ItemTemplate="{StaticResource UsersTemplate}"
                              ItemsSource="{Binding Users}"
                              />
                    </StackPanel>
                </Grid>
                <Grid Grid.Column="1">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <ListView Grid.Row="0"  BorderBrush="#cccccc" ItemsSource="{Binding Messages}" ItemTemplate="{StaticResource MessagesTemplate}"  
                          ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.CanContentScroll="True" 
                          ap:ScrollHelper.AutoScrollToEnd="True"
                          />
                    <StackPanel Grid.Row="1" Background="#fff">
                        <TextBox Margin="10" Height="32" VerticalContentAlignment="Center" Text="{Binding SingleMessage, UpdateSourceTrigger=PropertyChanged}" >
                            <TextBox.InputBindings>
                                <KeyBinding Key="Enter" Command="{Binding SendMessageCommand}"/>
                            </TextBox.InputBindings>
                        </TextBox>
                    </StackPanel>
                </Grid>
            </Grid>
        </Grid>
    </Border>
</Window>

